package com.gxd.business.websocket.controller;

import com.gxd.business.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/socket")
public class WebSocketController {

    @Autowired
    private WebSocketServer webSocketServer;

    @GetMapping("/pushMessage")
    public void pushMessage(@RequestParam(value = "userId") String userId,
                            @RequestParam(value = "cmd", defaultValue = "") String cmd,
                            @RequestParam(value = "msgTxt",required = false, defaultValue = "") String msgTxt) {
        webSocketServer.pushMessage(userId, webSocketServer.formatMessage(cmd, msgTxt));

    }

}
